﻿using sql_data_generator.FieldOptions;
using sql_data_generator.Generators;

namespace sql_data_generator.Randomizers
{
    public class RandomizerDateTime : BaseRandomizer<FieldOptionsDateTime>, IRandomizer
    {
        private const string Format = "yyyy-M-dd hh:mm:ss";
        private readonly RandomDateTimeGenerator _generator;

        public RandomizerDateTime(FieldOptionsDateTime options)
            : base(options)
        {
            _generator = new RandomDateTimeGenerator(options.DateFrom, options.DateTo);
        }

        public object GetData()
        {
            var value = _generator.Generate();

            return IsNull() ? null : (Options.IncludeTime ? value : value.Date).ToString(Format);
        }
    }
}